package Year22_Month06.day18;

public class 翻转二叉树 {
    public TreeNode invertTree(TreeNode root) {
        if(root == null) return null;
        //这里前中后序遍历都可以，我用的是前序遍历
        swap(root);
        invertTree(root.left);
        invertTree(root.right);
        return root;
    }

    public void swap(TreeNode node){
        TreeNode tmp = node.left;
        node.left = node.right;
        node.right = tmp;
    }
}
